package concurrencyPractice.chapter03;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 程序3-10 使用threadLocal维持线程封闭性
 * @date 2023/12/27 11:18:57
 */
public class ThreadLocalTest {

    static String DB_URl;
    private static ThreadLocal<Connection> connectionHolder = new ThreadLocal<Connection>() {
        @Override
        public Connection initialValue() {
            return DriverManager.getConnection(DB_URl);
        }
    };

    public static Connection getConnection() {
        return connectionHolder.get();
    }

}
